package com.pavan.nightgps;


import java.util.List;

import com.pavan.gps.GpsLocDetailsActivity;
import com.pavan.gps.addLoc;

import com.pavan.nightgps.ColorPickerDialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.Window;
import android.view.WindowManager;
import android.widget.DigitalClock;
import android.widget.Toast;

public class MMProjectActivity extends Activity {
    /** Called when the activity is first created. */
	
	
	
	public int textColor;
	public int textFont;
	
	
	
	//final int MENU_ALARM = 1;
    final int MENU_TEXT_COLOR = 2;
    final int MENU_TEXT_FONT_NORMAL = 3;
    final int MENU_TEXT_FONT_COMPUTER = 4;
    final int MENU_TEXT_FONT_SEGMENT = 5;
    final int MENU_TEXT_FONT_CHINTZYS = 6;
    final int MENU_TEXT_FONT_DIGITEK = 7;
    final int MENU_TEXT_FONT_ELECTRON = 8;
    final int MENU_GPSALARM = 9;
    final int DIALOG_COLOR_PICKER = 1;
    final int FONT_NORMAL=1;
    final int FONT_COMPUTER=2;
    final int FONT_SEGMENT= 3;
    final int FONT_CHINTZYS=4;
    final int FONT_DIGITEK=5;
    final int FONT_ELECTRON=6;
	    
	    
    public boolean onCreateOptionsMenu(Menu menu) {
    	//menu.add(0, MENU_ALARM, 0, "Alarm");
    	menu.add(0, MENU_TEXT_COLOR, 0, "Color");
    	
    	SubMenu fontMenu = menu.addSubMenu("Font");
    	fontMenu.add(0, MENU_TEXT_FONT_NORMAL, 0, "Normal");
    	fontMenu.add(0, MENU_TEXT_FONT_COMPUTER, 0, "Computer");
    	fontMenu.add(0, MENU_TEXT_FONT_SEGMENT, 0, "Seven Segment");
    	fontMenu.add(0, MENU_TEXT_FONT_CHINTZYS, 0, "Chintzys");
    	fontMenu.add(0, MENU_TEXT_FONT_DIGITEK, 0, "Digitek");
    	fontMenu.add(0, MENU_TEXT_FONT_ELECTRON, 0, "Electron");
    	menu.add(0, MENU_GPSALARM, 0, "GPS Alarm");
   
    	return true;
    }
    public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		/*Window window = getWindow();
        WindowManager.LayoutParams lp = ((Window) window).getAttributes(); 
        lp.screenBrightness = .05f;  // 0 - 1 
        window.setAttributes(lp); 
	*/	  
	}
    
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) 
        {
        	//case MENU_ALARM:
	        	/*Intent i = new Intent();
		        i.setClassName("com.android.alarmclock", "com.android.alarmclock.AlarmClock");
	        	if(isIntentAvailable(i))
	        	{
	        		startActivity(i);
	        	}
	        	else
	        	{
	        		Context context = getApplicationContext();
	        		CharSequence text = "Sorry, this feature isn't enabled on your phone yet.";
	        		int duration = Toast.LENGTH_SHORT;

	        		Toast toast = Toast.makeText(context, text, duration);
	        		toast.show();
	        	}
	            return true;*/
	        case MENU_TEXT_COLOR:
	        	showDialog(DIALOG_COLOR_PICKER);
	            return true;
	        case MENU_TEXT_FONT_NORMAL:
	        	setTextFont(FONT_NORMAL);
	            return true;
	        case MENU_TEXT_FONT_COMPUTER:
	        	setTextFont(FONT_COMPUTER);
	            return true;
	        case MENU_TEXT_FONT_SEGMENT:
	        	setTextFont(FONT_SEGMENT);
	            return true;
	        case MENU_TEXT_FONT_CHINTZYS:
	        	setTextFont(FONT_CHINTZYS);
	            return true;
	        case MENU_TEXT_FONT_DIGITEK:
	        	setTextFont(FONT_DIGITEK);
	            return true;
	        case MENU_TEXT_FONT_ELECTRON:
	        	setTextFont(FONT_ELECTRON);
	            return true;
	        case MENU_GPSALARM:
	        	Intent intent;
	        	intent = new Intent(this, GpsLocDetailsActivity.class);
	            startActivity(intent);      
	          
	        	return true;
        }
        return false;
    }
    
    
   
    private ColorPickerDialog.OnColorChangedListener mColorChangedListener =
            new ColorPickerDialog.OnColorChangedListener() {
        		public void colorChanged(int color) {
                    textColor = color;
                    //mTimeDisplay.setTextColor(textColor);
                    DigitalClock ta =(DigitalClock) findViewById(R.id.clock);
                    ta.setTextColor(textColor);
                    
                }
            };
            
            @Override
            protected Dialog onCreateDialog(int id) {
                switch (id) {
                case DIALOG_COLOR_PICKER:
                    return new ColorPickerDialog(this,
                            mColorChangedListener, textColor);
                }
                return null;
            }
        
    public boolean isIntentAvailable(Intent intent) {
        PackageManager packageManager = getPackageManager();
        List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    }
    
    void setTextFont(int fontNum)
    {
    	textFont = fontNum;
    	Typeface tf;
    	switch(textFont)
	    {
	    	case FONT_NORMAL:
	    		tf = Typeface.MONOSPACE;
	    		break;
	    	case FONT_COMPUTER:
	    		tf = Typeface.createFromAsset(getAssets(), "OCRAEXT.TTF");
	    		DigitalClock tv =(DigitalClock) findViewById(R.id.clock);
	    	        tv.setTypeface(tf);
	    		break;
	    	case FONT_SEGMENT:
	    		tf = Typeface.createFromAsset(getAssets(), "DS-DIGIT.TTF");
	    		DigitalClock ta =(DigitalClock) findViewById(R.id.clock);
	    		ta.setTypeface(tf);
	    		break;
	    	case FONT_CHINTZYS:
	    		tf = Typeface.createFromAsset(getAssets(), "chintzys.ttf");
	    		DigitalClock tb =(DigitalClock) findViewById(R.id.clock);
	    		tb.setTypeface(tf);
	    		break;
	    	case FONT_DIGITEK:
	    		tf = Typeface.createFromAsset(getAssets(), "DIGITEK.TTF");
	    		DigitalClock tc =(DigitalClock) findViewById(R.id.clock);
	    		tc.setTypeface(tf);
	    		break;
	    	case FONT_ELECTRON:
	    		tf = Typeface.createFromAsset(getAssets(), "electron 8f.ttf");
	    		DigitalClock td =(DigitalClock) findViewById(R.id.clock);
	    		td.setTypeface(tf);
	    		break;
	    }
    	
    	
	 }
    
}